function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}
//得到当前的日期
function getNowDate() {
  var date = new Date();
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  return [year, month, day].map(formatNumber).join('-')
}
//得到当前的日期
function getMorenDate() {
  var date = new Date();
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var day = date.getDate();
  return year + '年' + month + '月' + day+'日'
}
//得到选中的日期
function getSelectDate(riqi) {
  var date = riqi.split('-');
  var year = date[0];
  var month = date[1];
  var day = date[2];
  return year + '年' + month + '月' + day + '日'
}
//得到日期的年
function getSelectYear(riqi) {
  var date = riqi.split('-');
  var year = parseInt(date[0]);
  return year
}
//得到日期的月
function getSelectMonth(riqi) {
  var date = riqi.split('-');
  var month = parseInt(date[1]);
  return month
}
//得到日期的日
function getSelectDay(riqi) {
  var date = riqi.split('-');
  var day = parseInt(date[2]);
  return day
}
//得到2日期比较
function getCompairDate(start,end) {

  var onedate = Date.parse(start);
  var twodate = Date.parse(end);

  if (onedate >= twodate){
    return false;
  }else{
    return true;
  }
}
//得到当前的时间
function getNowTime() {
  var date = new Date();
  var hour = date.getHours()
  var minute = date.getMinutes()
  return [hour, minute].map(formatNumber).join(':')
}
//转换为数字
function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}
//得到今天的日期
function getNowDay() {
  var date = new Date();
  var month = date.getMonth() + 1
  var day = date.getDate()
  return [month, day].map(formatNumber).join('-')
}
//得到明天的日期
function getNextDay() {
  var date = new Date();
  date.setDate(date.getDate() + 1);
  var month = date.getMonth() + 1
  var day = date.getDate();
  return [month, day].map(formatNumber).join('-')
}
//得到后天的日期
function getLastDay() {
  var date = new Date();
  date.setDate(date.getDate() + 2);
  var month = date.getMonth() + 1
  var day = date.getDate()
  return [month, day].map(formatNumber).join('-')
}

module.exports = {
  formatTime: formatTime,
  getNowDate: getNowDate,
  getNowTime: getNowTime,
  getMorenDate: getMorenDate,
  formatNumber: formatNumber,
  getSelectDate: getSelectDate,
  getCompairDate:getCompairDate,
  getSelectYear: getSelectYear,
  getSelectMonth: getSelectMonth,
  getSelectDay: getSelectDay,
  getNowDay: getNowDay,
  getNextDay:getNextDay,
  getLastDay: getLastDay
}